package com.fare.taluo.core.domain.crawl;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.dayatang.domain.Entity;
import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.core.domain.config.channel.SourceEntity;

/**
 * 适配器配置entity
 * @author lzl
 *
 */
@javax.persistence.Entity
@Table(name = "FDC_TASK_ADAPTER")
@SuppressWarnings("serial")
public class TaskAdapterEntity extends 
		com.fare.taluo.base.ddd.domain.baseentity.BaseEntity{

//	@Id
//	@GeneratedValue(strategy = GenerationType.AUTO, generator = FDC_SEQ_GEN)
//	@SequenceGenerator(name = FDC_SEQ_GEN, sequenceName = FDC_SEQUENCE)
//	@Column(name = "ID")
//	private Long id;
	
	@ManyToOne(targetEntity = SourceEntity.class)
	@JoinColumn(name = "SOURCE_ID") //渠道id号
	private SourceEntity  sourceId;
	
	@Column(name = "ADAPTER_NAME")//适配器名称
	private String adapterName;
	
	@Column(name = "ADAPTER_CLASS")//适配器路径和类名
	private String adapterClass;
	
	@Column(name = "ISENABLE")//0,可用  	 1,不可用   	 2,冻结
	private String isenable;
	
	@Column(name = "PRIORITY")//优先级
	private String priority;
	
	@Column(name = "CREATTIME")//创建时间
	private Date creattime;
	
	@Column(name = "UPDATETIME")
	private Date updatetime;//更新时间
	
	@Column(name = "REMARKS")//备注
	private String remarks;
	
	@Column(name = "VERSION")//版本
	private String version;
	
//	@ManyToOne(targetEntity =AdapterUploadedEntity.class)//上传关联类名
//	@JoinColumn(name = "adapter_upload_id")
	@Column(name = "adapter_upload_id")
	private Long adapterUploadId;
	
	// Constructors
	/** default constructor */
	public TaskAdapterEntity() {
	}

//	private static TaskAdapterEntityRepository taskAdapterRepository = 
	//		InstanceFactory.getInstance(TaskAdapterEntityRepository.class);

	private static TaskAdapterEntityRepository getTaskAdapterEntityRepository(){
		return InstanceFactory.getInstance(TaskAdapterEntityRepository.class);
	}
	public void remove(){
		getTaskAdapterEntityRepository().remove(this);
	}

	public void saveOrUpdateTaskInfoEntity() {
		getTaskAdapterEntityRepository().save(this);
	}
	
	public void  saveMorU(TaskAdapterEntity ftp){
		 try {
			 getTaskAdapterEntityRepository().saveMorU(ftp);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

	public List<TaskAdapterEntity> findTaskAdapterByConsdions(String sourceId,String isEnable,String adapterName,String adapterClass){
		return getTaskAdapterEntityRepository().findTaskAdapterByConsdions(sourceId, isEnable,adapterName,adapterClass);
	}
	
	
	public static TaskAdapterEntity get(long id){
		try {
			return getTaskAdapterEntityRepository().findTaskAdapterEntity(id);
		} catch (Exception e) {
			System.out.println("取不到TaskAdapterEntity");
			e.printStackTrace();
		}
		return null;
	}
//
//	public Long getId() {
//		return id;
//	}
//
//	public void setId(Long id) {
//		this.id = id;
//	}

	public SourceEntity getSourceId() {
		return sourceId;
	}

	public void setSourceId(SourceEntity sourceId) {
		this.sourceId = sourceId;
	}

	public String getAdapterName() {
		return adapterName;
	}

	public void setAdapterName(String adapterName) {
		this.adapterName = adapterName;
	}

	public String getAdapterClass() {
		return adapterClass;
	}

	public void setAdapterClass(String adapterClass) {
		this.adapterClass = adapterClass;
	}

	public String getIsenable() {
		return isenable;
	}

	public void setIsenable(String isenable) {
		this.isenable = isenable;
	}

	public String getPriority() {
		return priority;
	}

	public void setPriority(String priority) {
		this.priority = priority;
	}

	public Date getCreattime() {
		return creattime;
	}

	public void setCreattime(Date creattime) {
		this.creattime = creattime;
	}

	public Date getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(Date updatetime) {
		this.updatetime = updatetime;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public Long getAdapterUploadId() {
		return adapterUploadId;
	}

	public void setAdapterUploadId(Long adapterUploadId) {
		this.adapterUploadId = adapterUploadId;
	}

}